package main.katalog.model;


public class users {
	
	public int getUserID(String username, String password){
	  connection con;
	  int userID=-1;
	  String sql = "SELECT * FROM users WHERE name = '"+username+"' AND password = '"+password+"'";

	  try {
		  con = new connection();
		  con.setStatement(con.getConnect().createStatement());
		  con.setResultSet(con.getStatement().executeQuery(sql));
		  if(con.getResultSet().next()){
			  userID = con.getResultSet().getInt("userID");
			  con.close();
		  }
	  } catch (Exception e) {
		  // TODO Auto-generated catch block
		  e.printStackTrace();
	  }

	  return userID;
	}
	public String getUserName(int userID){
		String name="";
		connection con;
		String sql = "SELECT * FROM users WHERE userID = '"+userID+"'";
		try {
			con = new connection();
			con.setStatement(con.getConnect().createStatement());
			con.setResultSet(con.getStatement().executeQuery(sql));
			if(con.getResultSet().next()){
				name = con.getResultSet().getString("name");
				con.close();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return name;
	}
}
